home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / math1.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  898b  |  82 lines

  1. /* math1.c 4.5.3 */
  2. void main()
  3. {
  4.   int number1, number2, result, operator, error;
  5.  
  6.   printf("Please input two numbers!\n");
  7.   scanf("%d%d", &number1, &number2);
  8.   printf("And now the code for the operation!\n");
  9.   printf("1=Add, 2=Subtract, 3=Multiply, 4=Divide\n");
  10.   scanf("%d", &operator);
  11.   error = 1;
  12.   if(operator == 1) /* Addition */
  13.     {
  14.      result = number1 + number2;
  15.      error = 0;
  16.     }
  17.   if(operator == 2) /* Subtraction */
  18.     {
  19.      result = number1 - number2;
  20.      error = 0;
  21.     }
  22.   if(operator == 3) /* Multiplication */
  23.     {
  24.      result = number1 * number2;
  25.      error = 0;
  26.     }
  27.   if(operator == 4) /* Division */
  28.     {
  29.      result = number1 / number2;
  30.      error = 0;
  31.     }
  32.   if(error == 1) /* None of the above conditions  */
  33.   printf("Wrong Code! Input only numbers 1 - 4!\n");
  34. else
  35.   printf("The result is %d\n", result);
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.